package com.qf.day03;

public class VolatileDemo {

    //volatile   //本地内存A的数据同步到主内存
    private static volatile Integer flag = 1;//标记  //本地内存A的数据同步到主内存

    public static void main(String[] args)  throws InterruptedException {
        // main  线程A

        new Thread(new Runnable() {// 线程B
            @Override
            public void run() {
                System.out.println("我是子线程工作内存flag的值：" + flag);
                while(flag == 1){//flag == 1 无限循环
                }
                System.out.println("子线程操作结束..." + flag);
            }
        }).start();
        Thread.sleep(500);

        flag = 2;
        System.out.println("我是主线程工作内存flag的值：" + flag);
    }
}